package comp.part
{
	import flash.events.MouseEvent;
	
	import mx.containers.Canvas;
	import mx.controls.Image;
	import mx.events.FlexEvent;
	import mx.managers.PopUpManager;
	
	public class BaseWin extends Canvas{
		
		[Embed(source="assets/close.png")]
		private var closeImg:Class; 
		private var closeBtn:Image;
		
		public function BaseWin(){
			super();
			this.addEventListener(FlexEvent.CREATION_COMPLETE, init);
		}
		
		private function init(e:FlexEvent):void{
			this.removeEventListener(FlexEvent.CREATION_COMPLETE, init);
			this.setStyle("borderColor", "#C81113");
			this.setStyle("borderStyle", "solid");
			this.setStyle("borderThickness", "2");
			this.setStyle("cornerRadius", "5");
			this.setStyle("backgroundColor", "#ffffff");
			
			closeBtn = new Image();
			closeBtn.source = closeImg;
			closeBtn.x = this.width-18; 
			closeBtn.y = 2;
			closeBtn.buttonMode = true;
			closeBtn.useHandCursor = true;
			closeBtn.addEventListener(MouseEvent.CLICK, closeHandler);
			this.addChild(closeBtn);
		}
		
		private function closeHandler(e:MouseEvent):void{
			close();
		}
		
		public function open():void{
			PopUpManager.addPopUp(this, Main.self, true);
			PopUpManager.centerPopUp(this);
		}
		
		public function close():void{
			if(closeBtn){
				closeBtn.addEventListener(MouseEvent.CLICK, closeHandler);
			}
			PopUpManager.removePopUp(this);
		}
		
	}
}